home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / IFF2PBM.ZIP / IFF2PBM.C < prev    next >
C/C++ Source or Header  |  1994-01-10  |  4KB  |  111 lines

  1. /*****************************************************************************
  2. **  Listing :   IFF2PBM.C                                                   **
  3. **  Funtion :   Convert ILBM-Picts (.LBM or .BBM) to PBM- and PAL-files.    **
  4. **  Notes   :   XLib && ACK needed !!!                                      **
  5. **  Author  :   JuHu (cn1.serv2.inf.tu-dresden.de)                          **
  6. **                                                                          **
  7. **  (C) 01/1994 ViNaSoft *****************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <dos.h>
  11. #include <mem.h>
  12. #include <ctype.h>
  13. #include <alloc.h>
  14. #include "xlib_all.h"       /* from XLib    */
  15. #include "ackiff.h"         /* from ACK3D   */
  16.  
  17.  
  18. extern unsigned char far  colordat[768];  /* globale PAL-array from ACKIFF.C */
  19.  
  20. int widthFour(int width)
  21. { return    (width + (((4-(width % 4)) == 4) ?
  22.             0 : (4-(width%4))));             /* smallest mult of 4 > width! */
  23. }
  24.  
  25. int main(int argc,char *argv[])
  26. {
  27.     int i,j,handle;
  28.     int height,width;
  29.     int width4,widthdiv4;
  30.     unsigned char ch;
  31.     long miscNumber = 0;
  32.     long bufferIndex = 0;
  33.     long bytesLeft;
  34.     long planSize;
  35.     unsigned char far *Picture;
  36.     unsigned char far *pbm;
  37.  
  38.     printf("IFF2PBM 1.0 (C) ViNaSoft by JuHu:-)\n");
  39.  
  40.     if(argc < 3)
  41.     { printf("Usage: IFF2SPR <ILBM file> <PBM file> [PAL file]\n");
  42.       printf("Note :\n");
  43.       printf("  -ILBM file is a .LBM or .BBM file. ( from DPaintII )\n");
  44.       printf("  -PBM  file is a planar bitmap file.( from XLib     )\n");
  45.       printf("  -PAL  file is a palette file.\n");
  46.       exit(0);
  47.     }
  48.     printf("Please wait...\n");
  49.     Picture = AckReadIff(argv[1]);   /* Load a Deluxe Paint picture  */
  50.  
  51.     if (Picture == NULL)             /* Whoops, got a problem    */
  52.     { printf("IFF2PBM: Not enought memory to load input file or\n");
  53.       printf("         input file isn't ILBM-file !\n");
  54.       exit(0);
  55.     }
  56.  
  57.     width   =   *((int *)&Picture[0]);
  58.     height  =   *((int *)&Picture[2]);
  59.     width4      = widthFour(width);
  60.  
  61.     if((pbm = farcalloc((long)width4 * (long)height + 2,1))==NULL)
  62.     {   printf("IFF2PBM: Not enought memory to convert !\n");
  63.         exit(0);
  64.     }
  65.     pbm[0]      = width4/4;
  66.     pbm[1]      = height;
  67.     planSize    = (long)width*(long)height/4;
  68.  
  69.     for(i=0;i<height;i++)
  70.       for(j=0;j<width;j++)
  71.       { ch = *(Picture+4+(long)i*(long)width+j);
  72.         *(pbm+2+(((long)i*(long)width+j)%4)*(long)planSize+((long)i*(long)width+j)/4) = ch;
  73.       }
  74.  
  75.     if((handle=f_open(argv[2],F_WRONLY))==FILE_ERR)
  76.     {   printf("IFF2PBM: Unable to open output PBM-file.\n");
  77.         exit(0);
  78.     }
  79.  
  80. /**** for YAK-file from YakIcon! :-) ********
  81.     f_writefar(handle,"YARFILE   ",10);
  82.     f_writefar(handle,Picture,4);
  83. *********************************************/
  84.  
  85.     
  86.     for (bytesLeft = (long)width4 * (long)height+2 ; bytesLeft > 0;)
  87.       {
  88.         miscNumber = (bytesLeft < 32000) ? bytesLeft : 32000;
  89.         f_writefar(handle,pbm + bufferIndex, (int)miscNumber);
  90.         bytesLeft -= miscNumber;
  91.         bufferIndex += miscNumber;
  92.       }
  93.     f_close(handle);
  94.     printf("IFF2PBM:    PBM-file -> %s........OK\n",argv[2]);
  95.  
  96.     if(argc >3)
  97.     {  if((handle=f_open(argv[3],F_WRONLY))==FILE_ERR)
  98.        {    printf("IFF2PBM: Unable to open output PAL-file .");
  99.             exit(0);
  100.        }
  101.        f_writefar(handle,colordat,768);
  102.        f_close(handle);
  103.        printf("IFF2PBM:    PAL-file -> %s........OK\n",argv[3]);
  104.     }
  105.     printf("Done.\n");
  106.     exit(0);
  107. }
  108.  
  109.   
  110.  
  111.